<?php
/**
* ================================
* 模块名称：会员专栏 space.php
* 程序内核：PHPCMS V9 gbk
* 模块内容：会员专栏 space.php ，专栏模板 space.html 等
* 模块制作：奋斗的十二
* 技术支持：http://www.e553.com
*/
defined('IN_PHPCMS') or exit('No permission resources.');
class space 
{
	private $db,$content_check_db,$friend_model,$username;
	function __construct() {
		$this->db = pc_base::load_model('content_model');
		$this->_userid = param::get_cookie('_userid');
		$this->_username = param::get_cookie('_username');
		$this->_groupid = param::get_cookie('_groupid');
		$this->content_check_db = pc_base::load_model('content_check_model');
		$this->friend_model = pc_base::load_model('space_friend_model');
		$this->siteid = intval($_GET[siteid]) ? intval($_GET[siteid]) : get_siteid();
		$this->username = $_GET['username']?addslashes(urldecode($_GET['username'])):$_username;//当前查看的个人空间会员用户名
		$this->wo = ($this->username == $this->_username) ? '我' : '亲';
		$this->show  = ($this->username == $this->_username) ? 1 : 0;
		 $info = $this->friend_model->get_one(array('fname'=>$this->username,'username'=>$this->_username),'username');
		 $this->guanzu = $info ? 1 : 0;
	}
	
	public function init()
	{
		$_userid = $this->_userid;
		$_username = $this->_username;
		$_groupid = $this->_groupid;
		$wo = $this->wo;
		$show = $this->show;
		$guanzu=$this->guanzu;
		$username = $this->username;
		$memberinfo=get_memberinfo_buyusername($username);
		$userid=$memberinfo['userid'];
		$useridimg=get_memberavatar($memberinfo['userid']);
		$nickname = $memberinfo['nickname'] ? $memberinfo['nickname'] : $username ;
		$siteid = $this->siteid;
		if(!$siteid) $siteid = 1;
		$CATEGORYS = getcache('category_content_'.$siteid, 'commons');
		$siteurl = siteurl($siteid);
		$pagesize = 20;
		$page = 0;
		
		$infos = $this->content_check_db->listinfo(array('siteid'=>$siteid,'catid'=>7),'inputtime DESC',$page);
		$datas = array();
		foreach($infos as $_v) {
			$arr_checkid = explode('-',$_v['checkid']);
			$_v['id'] = $arr_checkid[1];
			$_v['modelid'] = $arr_checkid[2];
			$_v['url'] = $_v['status']==99 ? go($_v['catid'],$_v['id']) : APP_PATH.'index.php?m=content&c=index&a=show&catid='.$_v['catid'].'&id='.$_v['id'];
			if(!isset($setting[$_v['catid']])) $setting[$_v['catid']] = string2array($CATEGORYS[$_v['catid']]['setting']);
			$workflowid = $setting[$_v['catid']]['workflowid'];
			$datas[] = $_v;
		}
		//print_r($datas);
		
		$SEO = seo($siteid, $catid, $username.'的空间', $memberinfo['description']);
		include template('space', 'space');
	}
	
	
	public function guanzu1()
	{
		$_userid = $this->_userid;
		$_username = $this->_username;
		$_groupid = $this->_groupid;
		$siteid = $this->siteid;
		if(!$siteid) $siteid = 1;
		$username = urldecode($_GET['username']);
		$uid = $_GET['uid'];
		$n = $_GET['n'];
		if(!$_username) 
		{
			echo 3;exit;
		}
		if($_username == $username) 
		{
			echo 4;exit;
		}
		 $info = $this->friend_model->get_one(array('fname'=>$username,'username'=>$_username),'username');
		if($info)
		{
			echo 2;exit;
		}
		$check_data = array(
				'username'=>$_username,
				'fname'=>$username,
				'userid'=>$_userid,
				'fuserid'=>$uid,
				'inputtime'=>time(),
				'regip'=>ip()
				);
				$result = $this->friend_model->insert($check_data);
				if($result)
				{
					$this->friend_model->query("UPDATE v9_member SET FENSI = FENSI+1 WHERE username='".$username."'");
					$this->friend_model->query("UPDATE v9_member SET GUANZU = GUANZU+1 WHERE username='".$_username."'");
					echo 2;
				}
				else
				{
					echo 1;
				}
		
	}	
	public function guanzu()
	{
		$_userid = $this->_userid;
		$_username = $this->_username;
		$_groupid = $this->_groupid;
		$siteid = $this->siteid;
		if(!$siteid) $siteid = 1;
		$username = $this->username;
		$page = intval($_GET['page']);
		include template('space', 'guanzu');
	}
	public function fensi()
	{
		$_userid = $this->_userid;
		$_username = $this->_username;
		$_groupid = $this->_groupid;
		$siteid = $this->siteid;
		if(!$siteid) $siteid = 1;
		$username = $this->username;
		$page = intval($_GET['page']);
		include template('space', 'fensi');
	}
	public function yaoqing()
	{
		$_userid = $this->_userid;
		$_username = $this->_username;
		$_groupid = $this->_groupid;
		$siteid = $this->siteid;
		if(!$siteid) $siteid = 1;
		$username = $this->username;
		$page = intval($_GET['page']);
		include template('space', 'yaoqing');
	}
}
?>